import 'package:flutter/material.dart';


import '../../resources/kq_theme_colors.dart';

class KqSelectButton extends StatelessWidget {
  ///边框间距
  final EdgeInsetsGeometry? padding;

  ///文本超出后样式,默认为超出省略末尾
  final TextOverflow? overflow;

  ///最大行高
  final int maxLines;

  ///按钮文案
  final String text;

  ///按钮对齐文本
  final Alignment? alignment;

  ///文案大小默认14
  final double fontSize;

  ///背景色
  final Color backgroundColor;

  ///文案颜色
  final Color textColor;

  ///边框颜色
  final Color bordColor;

  ///选中背景色,默认为f4f4f4
  final Color? selectBackgroundColor;

  ///选中边框颜色
  final Color? selectBordColor;

  ///选中文案颜色
  final Color? selectTextColor;

  ///是否可点默认为true
  final bool isEnable;

  ///选中状态
  final bool isSelect;

  ///弧度，默认为0
  final double? radius;

  /// 点击回调
  final VoidCallback? onTap;

  const KqSelectButton({
    Key? key,
    this.padding,
    this.radius,
    this.overflow = TextOverflow.ellipsis,
    this.maxLines = 1,
    required this.text,
    this.fontSize = 14,
    this.alignment = Alignment.center,
    this.backgroundColor = KqThemeColors.bgWhite,
    this.textColor = KqThemeColors.text26,
    this.bordColor = KqThemeColors.bgTransparent,
    this.isSelect = false,
    this.selectBackgroundColor = KqThemeColors.bgF4,
    this.selectTextColor,
    this.selectBordColor,
    this.isEnable = true,
    this.onTap,
  }) : super(key: key);

  Color? getBackgroundColor(bool select) {
    if (select) {
      if (selectBackgroundColor == null) {
        return backgroundColor;
      } else {
        return selectBackgroundColor;
      }
    } else {
      return backgroundColor;
    }
  }

  Color? getTextColor(bool select) {
    if (select) {
      if (selectTextColor == null) {
        return textColor;
      } else {
        return selectTextColor;
      }
    } else {
      return textColor;
    }
  }

  getBordColor(bool select) {
    if (select) {
      if (selectBordColor == null) {
        return bordColor;
      } else {
        return selectBordColor;
      }
    } else {
      return bordColor;
    }
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: isEnable ? onTap : () {},
      child: Container(
        padding: padding,
        alignment: alignment,
        decoration: BoxDecoration(
            color: getBackgroundColor(isSelect),
            borderRadius: BorderRadius.all(Radius.circular(radius ?? 0)),
            border: Border.all(width: 1, color: getBordColor(isSelect))),
        child: Text(
          text,
          maxLines: maxLines,
          overflow: overflow,
          style: TextStyle(
            color: getTextColor(isSelect),
            fontSize: fontSize,
          ),
        ),
      ),
    );
  }
}
